<?php

class MemberModel extends  Model{
	
	public $table='user';
	
	public $validate=array(
	
		array('tick','nonull','请勾选同意美丽说注册条款',2,3),
		array('username','nonull','用户名不能为空',2,3),
		array('nickname','nonull','昵称不能为空',2,3),
		array('password','nonull','密码不能为空',2,3),
		array('cpassword','nonull','确认密码不能为空',2,3),
		
	);
	
	public function validate_register(){
		
		if(!$this->create()) return FALSE;
		
		$password=Q('post.password','','md5');
		$cpassword=Q('post.cpassword','','md5');
		if($password!=$cpassword) {
			$this->error='两次密码不一致，请重新输入';
			return FALSE;
		}
		
		$username=Q('post.username');
		
		$data=$this->where(array('username'=>$username))->find();
		
		if($data) {
			$this->error='用户名已存在';
			return FALSE;
		}
		
		return $this->add();
	}
	
	
	public function validate_login(){
		
		$username=Q('post.username');
		
		$password=Q('post.password');
		
		$code=strtoupper(Q('post.code'));
		
		if(empty($username)){
			$this->error='用户名不能为空';
			return FALSE;
		}
		if(empty($password)){
			$this->error='密码不能为空';
			return FALSE;
		}
		
		if($code!=$_SESSION['code']){
			$this->error='验证码不正确';
			return FALSE;
		}
		
		$data=$this->where(array('username'=>$username))->find();
		if(!$data ||$data['password']!=md5($password)){
			$this->error='账户密码不正确，请重新输入';
			return FALSE;
		}
		return $data;
	}
	
	
}











